package com.yunpeng.aidevice.biz.service.impl;

import com.yunpeng.aidevice.biz.service.IDeviceDataCenterBizService;
import com.yunpeng.aidevice.common.constant.QueryConstants;
import com.yunpeng.common.dto.Result;
import com.yunpeng.aidevice.common.dto.query.*;
import com.yunpeng.aidevice.common.enums.DeviceUploadDataStateEnum;
import com.yunpeng.common.enums.QueryOperatorEnum;
import com.yunpeng.common.paging.PagingQueryDTO;
import com.yunpeng.common.paging.query.QueryParam;
import com.yunpeng.aidevice.dao.service.IListQueryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * DeviceDateCenterBizServiceImpl
 *
 * @author : Moore(hemw)
 * @date : 2020-04-28
 */
@Service
public class DeviceDateCenterBizServiceImpl implements IDeviceDataCenterBizService {

    @Resource
    private IListQueryService listQueryService;


    @Override
    /**
     * 设备单日详情数据
     *
     * @param deviceDayDetailQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryDeviceDayRecordDetail(DeviceDayDetailQueryDTO deviceDayDetailQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (deviceDayDetailQueryDTO.getProduceDate() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceDayDetailQueryDTO.getProduceDate(), QueryOperatorEnum.DAY_EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayDetailQueryDTO.getOrgCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("u", "organization_code",
                    deviceDayDetailQueryDTO.getOrgCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayDetailQueryDTO.getDeviceCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "code",
                    deviceDayDetailQueryDTO.getDeviceCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayDetailQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    deviceDayDetailQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayDetailQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    deviceDayDetailQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("d", "flag", 1, QueryOperatorEnum.EQUALS));
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.update_time", "desc");
        orderByMap.put("t.id", "desc");
        pagingQueryDTO.setCurrentPage(deviceDayDetailQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(deviceDayDetailQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_DEVICE_DAY_DETAIL_RECORD, null);
        return Result.success(resultData);
    }

    @Override
    /**
     * 统计单日设备通行数据
     *
     * @param deviceDayCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryDeviceDayCount(DeviceDayCountQueryDTO deviceDayCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (deviceDayCountQueryDTO.getProduceDate() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceDayCountQueryDTO.getProduceDate(), QueryOperatorEnum.DAY_EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayCountQueryDTO.getDeviceNumber())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "number",
                    deviceDayCountQueryDTO.getDeviceNumber(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayCountQueryDTO.getDeviceName())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "name",
                    deviceDayCountQueryDTO.getDeviceName(), QueryOperatorEnum.LEFT_LIKE));
        }
        if (StringUtils.isNotBlank(deviceDayCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    deviceDayCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDayCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    deviceDayCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("d", "flag", 1, QueryOperatorEnum.EQUALS));
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "desc");
        orderByMap.put("t.deviceNumber", "desc");
        pagingQueryDTO.setCurrentPage(deviceDayCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(deviceDayCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        Object[] args = new Object[1];
        args[0] = DeviceUploadDataStateEnum.normal.getValue();
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_DEVICE_DAY_COUNT, args);
        return Result.success(resultData);
    }

    @Override
    /**
     * 统计多日设备通行数据
     *
     * @param deviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryDeviceDateRecordCount(DeviceDaysCountQueryDTO deviceDaysCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (deviceDaysCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceDaysCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (deviceDaysCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceDaysCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(deviceDaysCountQueryDTO.getDeviceNumber())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "number",
                    deviceDaysCountQueryDTO.getDeviceNumber(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDaysCountQueryDTO.getDeviceName())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "name",
                    deviceDaysCountQueryDTO.getDeviceName(), QueryOperatorEnum.LEFT_LIKE));
        }
        if (StringUtils.isNotBlank(deviceDaysCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    deviceDaysCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceDaysCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    deviceDaysCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("d", "flag", 1, QueryOperatorEnum.EQUALS));
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "desc");
        orderByMap.put("t.deviceNumber", "desc");
        pagingQueryDTO.setCurrentPage(deviceDaysCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(deviceDaysCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        Object[] args = new Object[1];
        args[0] = DeviceUploadDataStateEnum.normal.getValue();
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_DEVICE_DAY_COUNT, args);
        return Result.success(resultData);
    }

    @Override
    /**
     * 统计组织多日设备通行数据
     *
     * @param deviceOrgDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryOrgDeviceDayCount(DeviceOrgDaysCountQueryDTO deviceOrgDaysCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (deviceOrgDaysCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceOrgDaysCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (deviceOrgDaysCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    deviceOrgDaysCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(deviceOrgDaysCountQueryDTO.getOrgCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("o", "code",
                    deviceOrgDaysCountQueryDTO.getOrgCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceOrgDaysCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    deviceOrgDaysCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(deviceOrgDaysCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    deviceOrgDaysCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        queryParams.add(QueryParam.quickSetQueryParam("u", "id", 0, QueryOperatorEnum.GREATER_THAN));
        orderByMap.put("t.produceTime", "desc");
        orderByMap.put("t.orgNumber", "desc");
        pagingQueryDTO.setCurrentPage(deviceOrgDaysCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(deviceOrgDaysCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        Object[] args = new Object[1];
        args[0] = DeviceUploadDataStateEnum.normal.getValue();
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_ORG_DEVICE_DAY_COUNT, args);
        return Result.success(resultData);
    }

    @Override
    /**
     * 统计用户设备通行数据
     *
     * @param userDeviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryUserDeviceDayCountView(UserDeviceDaysCountQueryDTO userDeviceDaysCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (userDeviceDaysCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    userDeviceDaysCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (userDeviceDaysCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    userDeviceDaysCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(userDeviceDaysCountQueryDTO.getOrgCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("o", "code",
                    userDeviceDaysCountQueryDTO.getOrgCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(userDeviceDaysCountQueryDTO.getUserNumber())) {
            queryParams.add(QueryParam.quickSetQueryParam("u", "number",
                    userDeviceDaysCountQueryDTO.getUserNumber(), QueryOperatorEnum.LEFT_LIKE));
        }
        if (StringUtils.isNotBlank(userDeviceDaysCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    userDeviceDaysCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(userDeviceDaysCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    userDeviceDaysCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "asc");
        pagingQueryDTO.setCurrentPage(userDeviceDaysCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(userDeviceDaysCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_USER_DEVICE_DAY_COUNT_VIEW, null);
        return Result.success(resultData);
    }

    @Override
    /**
     * 组织设备日统计数据
     *
     * @param orgDeviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryOrgDeviceDayCountView(OrgDeviceDaysCountQueryDTO orgDeviceDaysCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (orgDeviceDaysCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    orgDeviceDaysCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (orgDeviceDaysCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    orgDeviceDaysCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(orgDeviceDaysCountQueryDTO.getOrgCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("o", "code",
                    orgDeviceDaysCountQueryDTO.getOrgCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(orgDeviceDaysCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "merchant_code",
                    orgDeviceDaysCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(orgDeviceDaysCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    orgDeviceDaysCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        queryParams.add(QueryParam.quickSetQueryParam("u", "id", 0, QueryOperatorEnum.GREATER_THAN));
        orderByMap.put("t.produceTime", "asc");
        pagingQueryDTO.setCurrentPage(orgDeviceDaysCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(orgDeviceDaysCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_ORG_DEVICE_DAY_COUNT_VIEW, null);
        return Result.success(resultData);
    }

    @Override
    /**
     * 商户设备日统计数据
     *
     * @param merchantDeviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryMerchantDeviceDayCount(MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (merchantDeviceCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (merchantDeviceCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("m", "code",
                    merchantDeviceCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    merchantDeviceCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "desc");
        pagingQueryDTO.setCurrentPage(merchantDeviceCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(merchantDeviceCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        Object[] args = new Object[1];
        args[0] = DeviceUploadDataStateEnum.normal.getValue();
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_MERCHANT_DEVICE_DAY_COUNT, args);
        return Result.success(resultData);
    }

    @Override
    /**
     * 商户设备汇总
     *
     * @param merchantDeviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryMerchantDeviceDaysRecordCount(MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (merchantDeviceCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (merchantDeviceCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("m", "code",
                    merchantDeviceCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    merchantDeviceCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getDeviceCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "code",
                    merchantDeviceCountQueryDTO.getDeviceCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "desc");
        pagingQueryDTO.setCurrentPage(merchantDeviceCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(merchantDeviceCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        Object[] args = new Object[1];
        args[0] = DeviceUploadDataStateEnum.normal.getValue();
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_MERCHANT_DEVICE_DAYS_RECORD_COUNT, args);
        return Result.success(resultData);
    }

    @Override
    /**
     * 商户体温走势
     *
     * @param merchantDeviceDaysCountQueryDTO
     * @return
     */
    public Result<PagingQueryDTO> queryMerchantRecordCountView(MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        PagingQueryDTO pagingQueryDTO = new PagingQueryDTO();
        List<QueryParam> queryParams = new ArrayList<>();
        LinkedHashMap<String, String> orderByMap = new LinkedHashMap<>(16);
        if (merchantDeviceCountQueryDTO.getProduceDateStart() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateStart(), QueryOperatorEnum.DAY_GREATER_AND_EQUALS_THAN));
        }
        if (merchantDeviceCountQueryDTO.getProduceDateEnd() != null) {
            queryParams.add(QueryParam.quickSetQueryParam("t", "produce_time",
                    merchantDeviceCountQueryDTO.getProduceDateEnd(), QueryOperatorEnum.DAY_LESS_AND_EQUALS_THAN));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getMerchantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("m", "code",
                    merchantDeviceCountQueryDTO.getMerchantCode(), QueryOperatorEnum.EQUALS));
        }
        if (StringUtils.isNotBlank(merchantDeviceCountQueryDTO.getTenantCode())) {
            queryParams.add(QueryParam.quickSetQueryParam("d", "tenant_code",
                    merchantDeviceCountQueryDTO.getTenantCode(), QueryOperatorEnum.EQUALS));
        }
        queryParams.add(QueryParam.quickSetQueryParam("t", "flag", 1, QueryOperatorEnum.EQUALS));
        orderByMap.put("t.produceTime", "asc");
        pagingQueryDTO.setCurrentPage(merchantDeviceCountQueryDTO.getCurrentPage());
        pagingQueryDTO.setPageSize(merchantDeviceCountQueryDTO.getPageSize());
        pagingQueryDTO.setConditionList(queryParams);
        pagingQueryDTO.setSortColumnMap(orderByMap);
        PagingQueryDTO resultData = listQueryService.query(pagingQueryDTO, QueryConstants.QUERY_MERCHANT_RECORD_COUNT_VIEW, null);
        return Result.success(resultData);
    }
}
